package demo.Socket_learn;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @Auther: hjy(lc))
 * @Date: 2022/8/16-08-16-9:23
 * @Description：demo.Socket_learn  服务端
 */
/*

 */
public class TcpServer{
    public static void main(String[] args) {
        ServerSocket server = null;
        try {
            server= new ServerSocket(6666);

            //等待客户端连接：服务端阻塞（直到客户端连接）
            System.out.println("服务端启动，正在等待连接");

            Socket accept = server.accept();       //客户端连接对象
            System.out.println(accept);
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                if(server != null){
                    server.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
